package com.zigong.app.ui.adapter.holder;

import android.content.Context;
import android.support.v4.content.ContextCompat;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;

import com.ruihang.generalibrary.ui.adapter.holder.BaseRecylerHolder;
import com.ruihang.generalibrary.ui.util.OnItemInternalClick;
import com.ruihang.generalibrary.ui.widget.CustomFontTextView;
import com.ruihang.generalibrary.utils.DateUtils;
import com.zigong.app.R;
import com.zigong.app.beans.FChannel;
import com.zigong.app.beans.FProgram;
import com.zigong.app.ui.utils.GlideUtil;

import java.sql.Date;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2017/7/13 0013.
 */

public class RadioLivingHolder extends BaseRecylerHolder<FChannel> implements View.OnClickListener {
    //    @BindView(R.id.item_tv_living_time)
//    protected CustomFontTextView time;
    @BindView(R.id.item_tv_living_title)
    protected CustomFontTextView title;
    @BindView(R.id.item_tv_living_on_air)
    protected CustomFontTextView onAir;
    @BindView(R.id.iv_logo)
    protected ImageView ivLogo;
    private final int txColorGray, txColorBlack;

    public RadioLivingHolder(Context context, View itemView) {
        super(context, itemView);
        txColorGray = ContextCompat.getColor(context, R.color.colorGray98);
        txColorBlack = ContextCompat.getColor(context, R.color.colorBlack22);
        itemView.setOnClickListener(this);
    }

    @Override
    protected void initInject() {
        ButterKnife.bind(this, itemView);
    }

    @Override
    public void setData(FChannel t) {
        title.setText(TextUtils.isEmpty(t.getChannelName()) ? "" : t.getChannelName());
//        GlideUtil.getGlideWith11Def(context, t.getChannelImage()).into(ivLogo);
        GlideUtil.getGlideWithSmall169Def(context, t.getChannelImage()).into(ivLogo);
//        Date dataDate = DateUtils.getDataDate(t, 0);
//        if (dataDate != null) {
//            String startTime = DateUtils.formatDate(dataDate, "HH:mm");
//            time.setText(TextUtils.isEmpty(startTime) ? "" : startTime);
//        } else {
//            time.setText("");
//        }
        //time.setText(TextUtils.isEmpty(t.getStartTime()) ? "" : t.getStartTime());
//        if (t.isHasOutTime()) {
//            title.setTextColor(txColorGray);
////            time.setTextColor(txColorGray);
//        } else {
//            title.setTextColor(txColorBlack);
////            time.setTextColor(txColorBlack);
//        }
    }

    @Override
    public void setData(FChannel t, int position, boolean isSelected) {
        super.setData(t, position, isSelected);
        onAir.setVisibility(isSelected ? View.VISIBLE : View.GONE);
    }

    @Override
    public void onClick(View v) {
        if (internalClick != null) {
            internalClick.onItemInternalClick(itemView, v, getAdapterPosition());
        }
    }

    @Override
    public RadioLivingHolder setInternalClick(OnItemInternalClick internalClick) {
        super.setInternalClick(internalClick);
        return this;
    }
}
